package com.ruoyi.session;

import com.ruoyi.po.Account;
import lombok.extern.slf4j.Slf4j;

/**
 * 描述：外部用户Session
 * @author 杨宸
 * @date 2025-02-12
 */
@Slf4j
public class ExternalAccountSession {

    /**
     * 外部用户Session对象
     */
    private static final ThreadLocal<Account> SESSION = new ThreadLocal<>();

    /**
     * 描述：获得外部用户
     * @author 杨宸
     * @date 2025-02-12
     */
    public static Account get() {
        try {
            return SESSION.get();
        } catch (Exception e) {
            log.error("[ExternalAccountSession.get]获得外部用户失败", e);
            return null;
        }
    }

    /**
     * 描述：设置外部用户
     * @author 杨宸
     * @date 2025-02-12
     */
    public static void set(Account account) {
        try {
            SESSION.set(account);
        } catch (Exception e) {
            log.error("[ExternalAccountSession.get]设置外部用户失败", e);
        }
    }

    /**
     * 描述：移除外部用户
     * @author 杨宸
     * @date 2025-02-12
     */
    public static void remove() {
        try {
            SESSION.remove();
        } catch (Exception e) {
            log.error("[ExternalAccountSession.get]移除外部用户失败", e);
        }
    }

}
